<?php

// echo("aaa")

//字符集
header('content-type:text/html;charset=utf-8');
//连接增产改查轮子
include './login_CRUD.php';
//连接数据库
$coon = connectDB('127.0.0.1','root','qq553408','test2106');
//获取表单数据
$nickname = $_POST["nickname"];//昵称
$username = $_POST["username"];//用户名
$password1 = $_POST["password1"];//密码1
$password2 = $_POST["password2"];//密码2
$faces = $_POST["faces"];//密码2

//设定cookie过期时间
$outtime = time()+60*60*24;

//查询login表单有没有这个用户名
$sql = "SELECT *FROM login WHERE `username` ='$username'"; 
$res = mysqli_query($coon,$sql);

//测试连接数据库连接失败
if(!$coon){
    die('error for mysql: ' . mysqli_error($coon));
}
//连接成功
else{
    //处理用户名比对结果
    $row = mysqli_fetch_assoc($res);
    //当结果为数据库没有
    if (!$row) {
        //且两次密码输入一样
        if($password1==$password2){
            //比对完成后，把前端数据处理完传到数据库
            $regSql = " INSERT INTO login(`nickname`,`username`,`password`,`faces`) value('$nickname','$username','$password1','$faces') ";
            mysqli_query($coon,$regSql);

            //设置cookie
            setcookie("login",1,$outtime,"/QQLB/src/pages");
            setcookie("username",$username,$outtime,"/QQLB/src/pages");
            setcookie("faces",$faces,$outtime,"/QQLB/src/pages");
            setcookie("nickname","$nickname",$outtime,"/QQLB/src/pages");
            //跳转主页
            header('location: ../pages/QQread-home.html');
        }else{
            setcookie("repeat",1,0,"/QQLB/src/pages");
            header('location: ../pages/register.html');
        }

    } else {
        setcookie("repeat",1,0,"/QQLB/src/pages");
           header('location: ../pages/register.html');

    }
}



?>